package abstractComponent;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import concreteComponents.Normal;

import ar.edu.unq.tpi.pconc.Channel;

abstract public class Actuador {

	static Map<String, Class<? extends Actuador>> map = new HashMap<String, Class<? extends Actuador>>();

	public static void main(String[] args) throws InstantiationException,
			IllegalAccessException {
		Set<Channel<Integer>> channels = new HashSet<Channel<Integer>>();
		
		map.put("Normal", Normal.class);
		Actuador instance = map.get(args[0]).newInstance();
		
		for (int n = 1;n < args.length;n++) {
			int i = Integer.parseInt(args[n]);
			channels.add(new Channel<Integer>(i));
		}
		while (true) {
			int[] array = new int[channels.size()];
			ArrayList<Integer> al = new ArrayList<Integer>();
			for (Channel<Integer> channel : channels){
				al.add(channel.receive());
			}
			for (int i = 0; i < al.size(); i++){
				array[i]= al.get(i);
				
			}
			instance.accion(array);
		}
	}

	public abstract void accion(int[] i);
}

